package com.superteam.mac.dao;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;


import com.superteam.mac.mode.Syspara;

public class SysParaDAO extends BaseDAO {
	
	public Syspara findSysPara()
	{
		try
		{
			Syspara para = (Syspara) this.getJdbcTemplate().queryForObject(
			    "select * from tbsyspara",
			    new RowMapper() {

			        public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
			        	Syspara para = new Syspara();
			        	para.setFactoryName(rs.getString("FactoryName"));
			        	para.setCheckTime(rs.getInt("CheckTime"));
			        	para.setReadInterval(rs.getInt("ReadInterval"));
			        	para.setRefresInterval(rs.getInt("RefreshInterval"));
			            return para;
			        }
			    });
		return para;
		}catch(Exception e)
		{
			return null;
		}
	}
	
	public boolean updateSyspara(Syspara para)
	{
		try
		{
		this.getJdbcTemplate().update(
		        "update tbsyspara set CheckTime=?,ReadInterval=?,RefreshInterval=? where FactoryName = ?", 
		        new Object[] {para.getCheckTime(),para.getReadInterval(),para.getRefresInterval(),para.getFactoryName()});
		return true;
		}catch(Exception e)
		{
			e.printStackTrace();
			return false;
		}
	}
}
